package com.umbr3lla.main.state;

import java.util.Collections;
import java.util.Vector;

import com.umbr3lla.main.state.cards.PlayerCard;
import com.umbr3lla.main.state.cards.ResourceCard;
import com.umbr3lla.main.state.cards.WeaponCard;

public class Player 
{
	public byte id;
	public byte health, maxHealth;
	public byte decorations;
	
	private PlayerCard playerCard;
	
	private Turn currentTurn = new Turn();
	private Turn nextTurn = new Turn();
	
	private Vector<ResourceCard> inventory = new Vector<ResourceCard>();
	private Vector<ResourceCard> discard = new Vector<ResourceCard>();
	private Vector<ResourceCard> hand = new Vector<ResourceCard>();
	private Vector<ResourceCard> playArea = new Vector<ResourceCard>();
	private Vector<WeaponCard> mansionExplorePile = new Vector<WeaponCard>();
	
	public Player(PlayerCard playerCard, byte id)
	{
		this.id = id;
		this.playerCard = playerCard;
	}
	
	//-------------------------------------------
	
	public void resetTurn()
	{
		currentTurn = nextTurn;
		nextTurn = new Turn();
	}
	
	public void startTurn()
	{
		drawHand();
		///get message from client that we are done
		
	}
	
	public void endTurn()
	{
		discardHand();
		//send message to client turns over
		
	}
	
	
	public Turn getCurrentTurn() {
		return currentTurn;
	}
	
	public Turn getNextTurn() {
		return nextTurn;
	}
	
	public void addWeaponToMansionExplorePile(WeaponCard weapon)
	{
		mansionExplorePile.add(weapon);
	}
	
	public boolean playCardFromHand(ResourceCard c)
	{
		c.playCardFromHand();
		
//		if(c.getType() == CARD_TYPES.ACTION)
//		{
//		}
//		else if(c.getType() == CARD_TYPES.AMMO)
//		{
//		}
//		else if(c.getType() == CARD_TYPES.ITEM)
//		{
//		}
//		else if(c.getType() == CARD_TYPES.WEAPON)
//		{
//		}
		
		return true;
	}
	
	
	//--------------------------------------------
	
	public void shuffleInventory()
	{
		Collections.sort(inventory);
	}
	
	public void shuffleDiscardIntoInventory()
	{
		while(discard.size() > 0)
		{
			inventory.add(discard.remove(0));
		}
		
		shuffleInventory();
	}
	
	public void drawHand()
	{
		for(int i=0; i < 5; i++)
		{
			if(inventory.size() > 0)
			{
				shuffleDiscardIntoInventory();
			}
			
			hand.add(inventory.remove(0));
		}
	}
	
	public void discardHand()
	{
		while(hand.size() > 0)
			discard.add(hand.remove(0));
	}
	
}
